package com.whf.android.jar.base.mvp;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.whf.android.jar.base.latte.BaseFragment;

/**
 * @author qf
 */
public abstract class BaseMvpFragment<M extends IModel, V extends IView, P extends BasePresenter<M, V>>
        extends BaseFragment implements BaseMvp<M, V, P> {


    protected P presenter;
    protected Bundle mBundle;

    /**
     * 判断上一个界面是否传过来bundle
     */
    protected boolean hasData;

    /**
     * 处理上一个页面传来的数据
     */
    protected void getData(Bundle bundle) {

    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        presenter = createPresenter();
        if (presenter != null) {
            presenter.registerModel(createModel());
            presenter.registerView(createView());
        }
        mBundle = getArguments();
        if (mBundle != null) {
            hasData = true;
            getData(mBundle);
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        if (presenter != null) {
            presenter.destroy();
        }
    }

}
